package com.pandora.common.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.pandora.framework.util.LogUtils;

/**
 * stream操作工具类
 * 
 * @author JingChenglong 2017/12/26 21:50
 *
 */
public class StreamUtils {

	public static void closeInputStream(InputStream inputStream) {

		if (inputStream != null) {
			try {
				inputStream.close();
			} catch (IOException e) {
				LogUtils.logError(CommonUtils.getTraceInfo() + e.getMessage());
			}
			inputStream = null;
		}
	}

	public static void closeOutputStream(OutputStream outputStream) {

		if (outputStream != null) {
			try {
				outputStream.close();
			} catch (IOException e) {
				LogUtils.logError(CommonUtils.getTraceInfo() + e.getMessage());
			}
			outputStream = null;
		}
	}

	public static void closeBufferedInputStream(BufferedInputStream bufferedInputStream) {

		if (bufferedInputStream != null) {
			try {
				bufferedInputStream.close();
			} catch (IOException e) {
				LogUtils.logError(CommonUtils.getTraceInfo() + e.getMessage());
			}
			bufferedInputStream = null;
		}
	}

	public static void closeBufferedOutputStream(BufferedOutputStream bufferedOutputStream) {

		try {
			bufferedOutputStream.close();
		} catch (IOException e) {
			LogUtils.logError(CommonUtils.getTraceInfo() + e.getMessage());
		}
	}

	public static void flush(BufferedOutputStream bufferedOutputStream) {

		try {
			bufferedOutputStream.flush();
		} catch (IOException e) {
			LogUtils.logError(CommonUtils.getTraceInfo() + e.getMessage());
		}
	}
}